﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using InformationRetrieval.Tokenizer;
using InformationRetrieval.Normalization;
using InformationRetrieval.Wildcard;
using InformationRetrieval.Indexer;
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace InformationRetrieval
{
    /// <summary>
    /// Demonstrates the differences between wildcard indizes
    /// </summary>
    public partial class Form2 : Form
    {
        #region Fields
        IWildcardIndex _wildcardIndex = null;  
        #endregion

        #region Constructor
        public Form2()
        {
            InitializeComponent();

        } 
        #endregion

        #region Eventhandler
        private void uxRawDocuments_TextChanged(object sender, EventArgs e)
        {
            if (_wildcardIndex is KGramIndex)
                _wildcardIndex = new KGramIndex();
            else _wildcardIndex = new PermutermIndex();
            PrintIndex();
        }

        private void uxKgram_Click(object sender, EventArgs e)
        {
            _wildcardIndex = new KGramIndex();
            PrintIndex();
        }

        private void uxPermuterm_Click(object sender, EventArgs e)
        {
            _wildcardIndex = new PermutermIndex();
            PrintIndex();
        } 
        #endregion

        #region Print Index
        private void PrintIndex()
        {
            if (_wildcardIndex != null)
            {
                ITokenizer tokenizer = new EnglishTokenizer();
                INormalizer normalizer = uxNormalizeText.Checked
                    ? new PorterStemmer()
                    : new DummyNormalizer() as INormalizer;

                using (StringReader reader = new StringReader(uxRawDocuments.Text))
                {
                    _wildcardIndex.AddTerms(tokenizer
                                            .Tokenize(reader, true)
                                            .Select(x => normalizer.Normalize(x.Token)));
                }

                uxOutput.Text = _wildcardIndex.ToString();
            }
        } 
        #endregion
    } 
}
